package com.ftg.learn;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.nio.charset.StandardCharsets;

/**
 *  用来测试发送消息
 * @author Guo
 * @date 2022/5/27
 */
public class ProductSend {

    /**
     * 数据生成者
     * @param args
     */
    public static void main(String[] args) {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("localhost");
        try (
                Connection c = cf.newConnection();
                Channel channel = c.createChannel()
        ){
            // 生成一个队列
            channel.queueDeclare("test1",false,false,false,null);
            channel.queueDeclare("test2",false,false,false,null);

            // 把队列里添加 "this is my first test1" 推送到 RabbitMQ中
            channel.basicPublish("","test1",null,"this is my first test1".getBytes(StandardCharsets.UTF_8));
            channel.basicPublish("","test2",null,"this is my first test2".getBytes(StandardCharsets.UTF_8));
        }catch (Exception ex){
            ex.printStackTrace();
        }

    }



}
